package com.dmz.workflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dmz.workflow.base.BaseServiceImpl;
import com.dmz.workflow.dao.WorkflowProcessRelationsMapper;
import com.dmz.workflow.service.WorkflowProcessRelationsService;
import com.dmz.workflow.entity.ProcessRelations;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WorkflowProcessRelationsServiceImpl extends BaseServiceImpl<WorkflowProcessRelationsMapper, ProcessRelations> implements WorkflowProcessRelationsService {

    @Autowired
    private WorkflowProcessRelationsMapper workflowProcessRelationsMapper;

    @Override
    public boolean queryProcessInstanceRelation(String processInstanceId, String userId) {
        Integer result = workflowProcessRelationsMapper.queryProcessInstanceRelation(processInstanceId, userId);
        return result > 0;
    }

    @Override
    public ProcessRelations queryProcessSessionId(String processInstanceId) {
        LambdaQueryWrapper<ProcessRelations> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProcessRelations::getProcessInstanceId, processInstanceId)
                .isNotNull(ProcessRelations::getSessionId);
        return workflowProcessRelationsMapper.selectOne(lambdaQueryWrapper);
    }
}
